
import json
from sanic import Websocket

from app.core.entity import ApiResult


class WebsocketData:
    websocket:Websocket
    currentUserId:int

    async def error(self,code=1,msg="失败",data={})->ApiResult:
        result=ApiResult.error(code,msg,data)
        self.websocket.send(json.dumps(result))

    async def send(self,data):
        await self.websocket.send(data)